<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Search</title>
<script type="text/javascript" language="javascript">
	var xmlhttp;
	window.onload = function() {
		createOption();
		document.getElementById("form").onsubmit = function() {
			return checkOption();
		};
	};
	
	function createOption() {
		if (window.XMLHttpRequest) {
			xmlhttp = new XMLHttpRequest();
		} else {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.open("POST", "/test/userOperateServlet?useroperate=search");
		xmlhttp.onreadystatechange = function () {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				/*DOM解析 */
				var ids = xmlhttp.responseXML.getElementsByTagName("ids")[0].childNodes;
				var select = document.getElementById("sid");
				select.length = 1;
				select.options[0].selected = true;
				for ( var i = 0; i < ids.length; i++) {
					var id = ids[i];
					var idvalue = id.firstChild.nodeValue;
					var option = document.createElement("option");
					option.appendChild(document.createTextNode(idvalue));
					option.setAttribute("value", idvalue);
					select.appendChild(option);
				}
			}
		};
		xmlhttp.send();
	}
	
	function checkOption() {
		/*如果选中的是第一个的话禁止提交(document.getElementsByTagName("select")[0].options['selectedIndex'].value可以取得选中的值 )*/
		var select = document.getElementById("sid").selectedIndex;
		if(select == 0){
			return false;
		}else{
			return true;
		}
	}
</script>
</head>
<body>
	<jsp:include page="header.jsp" />
	<form id="form" action="/test/userOperateServlet?useroperate=findstudent1" method="post">
		<select id="sid" name="id">
			<option value="0">请选择</option>
		</select> <input type="submit" value="查询">
		<label style="color:red">${student.id}:${student.name }</label>
	</form>
	
</body>
</html>
